package com.jacars.common.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @Author: zlt
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 错误消息
     */
    private String msg;
    /**
     * 业务数据
     *
     * @return
     */
    private T data;

    public static <T> Result<T> succeed(String msg) {
        return of(CodeEnum.SUCCESS.getCode(), msg, null);
    }

    public static <T> Result<T> succeed(T model, String msg) {
        return of(CodeEnum.SUCCESS.getCode(), msg, model);
    }

    public static <T> Result<T> succeed(T model) {
        return of(CodeEnum.SUCCESS.getCode(), "", model);
    }

    public static <T> Result<T> of(Integer code, String msg, T datas) {
        return new Result<>(code, msg, datas);
    }

    public static <T> Result<T> failed(String msg) {
        return of(CodeEnum.ERROR.getCode(), msg, null);
    }

    public static <T> Result<T> failed(T model, String msg) {
        return of(CodeEnum.ERROR.getCode(), msg, model);
    }
}
